package com.explore.demo.mapper;

import com.explore.demo.pojo.Recruitment;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author gaolainan
 * @since 2021-04-18
 */
public interface RecruitmentMapper extends BaseMapper<Recruitment> {


    /**
     * 通过分类拿到相关职位的简略信息
     * @param categoryName 类别的名称
     * @return
     */
    @Select("select * from recruitment where id in (select recruit_id from recruit_category where category_id = (select id from category where category_name = #{category_name}))")
    List<Recruitment> getAllRecruitmentInfo(String categoryName);

    /**
     * 获得最受欢迎的两个公司信息
     * @return
     */
    @Select("select * from recruitment where id in (select recruit_id from (select recruit_id from row_view ORDER BY read_num DESC limit 9) as recruit_id)")
    List<Recruitment> getTopRecruitmentList();


    /**
     * 根据招聘职位的id返回对应的
     * @param recruitId
     * @return
     */
    @Select("select category_name from category where id in (select category_id from recruit_category where recruit_id = #{recruitId})")
    List<String> getAllCategory(Integer recruitId);

    /**
     * 通过职位的id 返回对应的福利类别
     * @param recruitId
     * @return
     */
    @Select("select category_name from category where id in (select category_id from welfare_category where recruit_id = #{recruitId})")
    List<String> getAllWelfareCategory(Integer recruitId);


    /**
     * 根据地点查询对应的招聘信息
     * @param place
     * @return
     */
    @Select("select * from recruitment where work_city = #{place}")
    List<Recruitment> queryRecruitmentByPlace(String place);


    /**
     * 根据公司名称返回对应的招聘信息
     * @param companyName
     * @return
     */
    @Select("select * from recruitment where company_id in (select id from company where company_name = #{company})")
    List<Recruitment> getRecruitmentList(String companyName);

    /**
     * 查找指定用户的收藏的职位信息
     * @param account
     * @return
     */
    @Select("select * from recruitment where id in (select recruit_id from collect_relation where user_id = (select id from user where account = #{account}) and deleted = 0)")
    List<Recruitment> getNowUserStar(String account);

    /**
     * 拿到最新的职位信息
     * @return
     */
    @Select("select * from recruitment order by create_time desc limit 1")
    Recruitment getNewRecruitment();
}
